home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/env python
-
- #
- # This file is part of OpenVIP (http://openvip.sourceforge.net)
- #
- # Copyright (C) 2002-2003
- # Michal Dvorak, Jiri Sedlar, Antonin Slavik, Vaclav Slavik, Jozef Smizansky
- #
- # This program is licensed under GNU General Public License version 2;
- # see file COPYING in the top level directory for details.
- #
- # $Id: visualize.py,v 1.4 2003/06/19 13:37:23 vaclavslavik Exp $
- #
-
- #
- # This program visualizes OpenVIP processing network in the form of directed
- # graph. It doesn't do any validity checkings, so the input must be valid
- # .openvip file.
- #
- # Requires the "dot" program from graphviz package.
- #
-
- import xml.dom.minidom
- import sys, string, os
-
- if not (len(sys.argv) == 3 or
- (len(sys.argv) == 4 and sys.argv[1] in ['--brief','--very-brief'])):
- print "Usage: %s [--brief|--very-brief] input.openvip output.png" % sys.argv[0]
- sys.exit(1)
-
- showID = 1
- showParams = 1
- showConnectors = 1
-
- args = 0
- if sys.argv[1] == '--brief':
- showID = 0
- showParams = 0
- args += 1
- elif sys.argv[1] == '--very-brief':
- showID = 0
- showParams = 0
- showConnectors = 0
- args += 1
-
-
- tree = xml.dom.minidom.parse(sys.argv[args+1])
- root = tree.documentElement
-
-
- # colors in HSV:
- COLOR_NORMAL = "black"
- COLOR_INPUT = "blue"
- COLOR_OUTPUT = "red"
-
-
- output = """
- digraph network
- {
- bgcolor=white
- margin=10
- """
-
- class ModuleInfo:
- def __init__(self):
- self.cin = []
- self.cout = []
- mods = {}
-
- for n in root.getElementsByTagName('module'):
- mods[n.getAttribute('id')] = ModuleInfo()
-
- for n in root.getElementsByTagName('connect'):
- c = n.getAttribute('conn_in')
- if not c in mods[n.getAttribute('module_in')].cout:
- mods[n.getAttribute('module_in')].cout.append(c)
- c = n.getAttribute('conn_out')
- if not c in mods[n.getAttribute('module_out')].cin:
- mods[n.getAttribute('module_out')].cin.append(c)
-
- significantParams = {
- 'VideoFilter' : 'videofilter',
- 'AudioFilter' : 'audiofilter',
- 'VideoTransition' : 'transition',
- 'AudioTransition' : 'transition',
- 'Output' : 'format',
- }
-
- for n in root.getElementsByTagName('module'):
- m = mods[n.getAttribute('id')]
-
- if len(m.cin) == 0:
- color = COLOR_INPUT
- elif len(m.cout) == 0:
- color = COLOR_OUTPUT
- else:
- color = COLOR_NORMAL
-
- output += """%s [ shape=record,fontcolor="%s",fontsize=10,fontname="Helvetica",
- label=\"{{""" % (n.getAttribute('id'),color)
-
- if showConnectors:
- cons = []
- for c in m.cin:
- cons.append("<I%s> (%s)" % (c,c))
- output += string.join(cons,"|") + '}|'
-
- paramsDict = {}
- params = []
- for p in n.getElementsByTagName('param'):
- value = p.firstChild.data.replace('\\', '\\\\\\\\')
- params.append('%s=%s' % (p.getAttribute('name'), value))
- paramsDict[p.getAttribute('name')] = value
- if showParams:
- params = '|%s' % string.join(params, "\\n")
- else:
- params = ''
-
- klass = n.getAttribute('class')
- if showID:
- nameStr = '(%s)\\nclass=%s' % (n.getAttribute('id'), klass)
- else:
- nameStr = klass
-
- if not showParams and klass in significantParams:
- nameStr += ':%s' % paramsDict[significantParams[klass]]
-
- output += """%s%s""" % (nameStr, params)
-
- if showConnectors:
- output += '|'
- cons = []
- for c in m.cout:
- cons.append("<O%s> (%s)" % (c,c))
- output += '{' + string.join(cons,"|");
-
- output += """}}"];\n"""
-
-
- for n in root.getElementsByTagName('connect'):
- if showConnectors:
- output += """%s:O%s -> %s:I%s [];\n""" % (n.getAttribute('module_in'),
- n.getAttribute('conn_in'),
- n.getAttribute('module_out'),
- n.getAttribute('conn_out'))
- else:
- output += "%s -> %s [];\n" % (n.getAttribute('module_in'),
- n.getAttribute('module_out'))
-
-
- output += '}'
-
- tree.unlink()
-
- os.system("""dot -o %s -Tpng <<EOF
- %s
- EOF"""% (sys.argv[args+2], output))
-